package com.aaa.service.impl;

import com.aaa.dao.StaffDao;
import com.aaa.dao.impl.StaffDaoImpl;
import com.aaa.entity.Staff;
import com.aaa.service.StaffService;
import com.aaa.util.BusinessException;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StaffServiceImpl implements StaffService {

    private StaffDao staffDao = new StaffDaoImpl();
    private int len;

    @Override
    public Staff login(String staffId, String password) {
        return staffDao.login(staffId, password);
    }

    @Override
    public int updateStaffByStaffId(Staff staff) {
        int len = staffDao.updateStaffByStaffId(staff);
        return len;
    }


    @Override
    public Map<String, Object> getAllStaffInfo(Integer pageNumber, Integer pageSize, String searchStuno,
                                               String searchName) throws Exception {
        if (pageNumber == null || pageNumber == 0) {
            throw new BusinessException("当前页数不能为空");
        }
        if (pageSize == null || pageSize == 0) {
            throw new BusinessException("每页条数不能为空");
        }
        pageNumber = (pageNumber - 1) * pageSize;
        List<Staff> list = staffDao.getAllStaffInfo(pageNumber, pageSize, searchStuno, searchName);
        int count = staffDao.getAllStaffInfoCount(searchStuno, searchName);
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        map.put("count", count);
        return map;
    }

    @Override
    public int addStaffByStaffId(Staff staff) {
        int len = staffDao.addStaffByStaffId(staff);
        return len;
    }

    @Override
    public int deleteStaffById(int id) {
        int len = staffDao.deleteStaffById(id);
        return len;
    }
}
